var time;
efform_onload = function() {
	if ($('#flag').val() == 'hidden') {
		document.getElementById('ef_region_inqu').style.display = "none";
	}
};

button_query_onclick = function() {
	efgrid.submitInqu("ef_grid_result", "ZM", "ZMCG72", "query");
}

button_insert_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdOverTime = grid.getCellValueByColumnName(rows[i], "fdOverTime"); // 完成时间
		var fdHappenTime = grid.getCellValueByColumnName(rows[i], "fdHappenTime"); // 发生时间
		if(fdOverTime==null||fdOverTime==""){
			EFAlert("完成时间不能为空");
			return;
		}
		if(fdHappenTime==null||fdHappenTime==""){
			EFAlert("起始时间不能为空");
			return;
		}
		if (fdOverTime <= fdHappenTime) {
			EFAlert("完成时间不能早于发生时间");
			return;
		}
	}

	efgrid.submitForm("ef_grid_result", "ZM", "ZMCG72", "insert",true);
}
button_update_onclick = function() {

	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		var fdOverTime = grid.getCellValueByColumnName(rows[i], "fdOverTime"); // 完成时间
		var fdHappenTime = grid.getCellValueByColumnName(rows[i], "fdHappenTime"); // 发生时间
		if (fdOverTime <= fdHappenTime) {
			EFAlert("完成时间不能早于发生时间");
			return;
		}
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行修改！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCG72", "update",true);
}

button_delete_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0) return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行删除！");
			return;
		}
	}

	EFConfirm('你确认要删除吗?', '确认框',
	function(r) {
		if (r) {
			efgrid.submitForm("ef_grid_result", "ZM", "ZMCG72", "delete", true);
		}
	});
}

button_report_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0) return;
	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行生效！");
			return;
		}
	}

	EFConfirm('你确认要生效吗?', '确认框',
	function(r) {
		if (r) {
			efgrid.submitForm("ef_grid_result", "ZM", "ZMCG72", "report", true);
		}
	});
}

calcTime = function() {
	time = parseFloat(time) / 1000;
	time = parseInt(time / 3600.0)
			+ "小时"
			+ parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)
			+ "分钟"
			+ parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) - parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60)
			+ "秒";
}

// 单元格编辑后回调的方法
efgrid_onDataCellSaved = function(grid_id, row_index, col_index, cell_value) {
	var grid = efgrid.getGridObject(grid_id);
	if (col_index == 4 || col_index == 9) {
		var fdOverTime = grid.getCellValueByColumnName(row_index, "fdOverTime"); // 完成时间
		var fdHappenTime = grid.getCellValueByColumnName(row_index, "fdHappenTime"); // 发生时间
		time = new Date((fdOverTime).replace(/-/g, "/")) - new Date((fdHappenTime).replace(/-/g, "/"));
		calcTime();
		grid.setCellValue(row_index, 10, time, TYPE_DATA);
		grid.refreshCell(row_index, 10, TYPE_DATA);
	}
}

efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {
		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟");
			grid.getBlockData().setCell(rows[i], "fdCurrentDate", getCurrentDate());
		}
	}
	for (var i = 0; i < rows.length; i++) {
		grid.getBlockData().setCell(rows[i], "fdKeyId", "");
	}
}